﻿<%@ WebHandler Language="C#" Class="GeneralUser_update" %>

using System;
using System.Web;
using OneshoppingWeb;
using OneShoppingModel;
using OneShoppingBLL;
using OneShoppingUtility;
using System.Web.SessionState;

public class GeneralUser_update : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        bool result = false;
        try
        {
            SystemUser sysUser = (SystemUser)context.Session["user"];
            if (sysUser == null)
            {
                context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.NOT_LOG));//没有登入
            }
            else
            {
              int   roleId=Convert.ToInt32( context.Session["RoleId"]);
              if (roleId == 3)
              {
                  GeneralUser g = new GeneralUser();
                  string UserName = context.Request["UserName"];
                  g.UserId = sysUser.UserId;
                  g.UserName = UserName;
                  result = GeneralUserBLL.GetInstance().Update(g);
              }
              if (roleId == 2) {
                  BusinessUser b = new BusinessUser();
                  b.UserId = sysUser.UserId;
                  string UserName = context.Request["UserName"];
                  b.UserName=UserName;
                  String email = context.Request["Email"];
                  b.Email=email;
                  String storeName = context.Request["StroeName"];
                  b.StroeName=storeName;
                  result = BusinessUserBLL.GetInstance().Update(b);
              }
              if (roleId == 1) {
                  CompanyUser c = new CompanyUser();
                  c.UserId = sysUser.UserId;
                  String realName = context.Request["RealName"];
                  c.RealName = realName;
                  result = CompanyUserBLL.GetInstance().Update(c);
              }
                
                if (result)
                {
                    context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.UPDATEBUSINESSUSER_SUCCESS));//更新成功
                }
                else
                {
                    context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.UPDATEBUSINESSUSER_FAIL));//更新失败
                }
            }
        }
        catch
        {
            context.Response.Write(UtilityJson.ResultToJson((int)Protocol_user.NOT_LOG));//没有登入
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}